package cn.hxzy.course.mapper;

import cn.hxzy.common.domain.FileInfo;
import cn.hxzy.common.domain.Section;
import cn.hxzy.common.domain.Task;
import cn.hxzy.common.domain.vo.TaskVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author niuyi
 * @since 2024-06-22
 */
public interface TaskMapper extends BaseMapper<Task> {

    //查询作业详情
    @Select("select * from sys_task where task_id=#{taskId}")
//    @Results({
//    @Result(property = "section",column = "section_id",
//            javaType = Section.class,
//            one = @One(select = "cn.hxzy.mapper.SectionMapper.selectById"))
//    })
    TaskVo selectTaskVo(Integer taskId);

   
    //视频名称模糊查询
    @Select("SELECT \n" +
            "    t.task_id,\n" +
            "    t.task_name,\n" +
            "    t.task_info\n" +
            "FROM \n" +
            "    sys_course AS c\n" +
            "JOIN \n" +
            "    sys_chapter AS ch ON c.course_id = ch.course_id\n" +
            "JOIN \n" +
            "    sys_section AS s ON ch.chapter_id = s.chapter_id\n" +
            "JOIN \n" +
            "    sys_task AS t ON s.section_id = t.section_id\n" +
            "WHERE \n" +
            "    c.course_id = #{courseId}\n" +
            "    AND t.task_name LIKE '%${taskName}%'\n" +
            "    AND c.deleted = 0\n" +
            "    AND ch.deleted = 0;")
    List<Task> selectTask(String taskName,Integer courseId);

    //查此课程所有作业
    @Select("SELECT COUNT(0) FROM sys_task WHERE section_id IN(\n" +
            "SELECT section_id FROM sys_section WHERE chapter_id IN(\n" +
            "SELECT chapter_id FROM sys_chapter WHERE course_id=#{courseId}))")
    double selectCount(Long courseId);

    @Select("select * from sys_task where section_id=#{sectionId}")
    List<Task> getList(int sectionId);

    //删除作业
    @Delete("DELETE FROM sys_task WHERE task_id=#{taskId}")
    int deleteTask(Integer taskId);
}
